package org.leyi.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.leyi.shop.common.exception.BusinessException;
import org.leyi.shop.common.response.BaseResponse;
import org.leyi.shop.common.response.EnumResponse;
import org.leyi.shop.model.pojo.Product;
import org.leyi.shop.service.ProductService;
import org.leyi.shop.util.BaseResponseUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
@CrossOrigin(allowCredentials = "true",origins = {"http://localhost:5173"})
public class ProductController {
    @Resource
    private ProductService productService;
    @GetMapping("{shopId}")
    public BaseResponse<List<Product>> getTargetShopProduct(@PathVariable Long shopId)
    {
        if(shopId<=0)
        {
            throw new BusinessException(EnumResponse.PARAMETER_ERR);
        }
        return BaseResponseUtils.success(productService.list(new QueryWrapper<Product>().eq("store_id",shopId)),"请求数据成功");
    }
}
